package com.gpnu.controller;

import com.gpnu.pojo.CURDResult;
import com.gpnu.pojo.CourseOrder;
import com.gpnu.pojo.PageResult;
import com.gpnu.service.CourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/courseOrder")
public class CourseOrderController {

    @Autowired
    CourseOrderService orderService;

    @RequestMapping("/list")
    public String list() {
        return "courseOrder/list";
    }

    @RequestMapping("/add")
    public String add() {
        return "courseOrder/add";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public CURDResult delete(String order_id) {
        CURDResult result = new CURDResult();

        CourseOrder order = orderService.deleteByOrderId(order_id);

        return result;
    }

    @RequestMapping("/save")
    @ResponseBody
    public CURDResult save(CourseOrder order) {
        CURDResult result = new CURDResult();
        System.out.println(order);
        orderService.save(order);
        return result;
    }

    @RequestMapping("/detail")
    public String detail(Model model, String order_id) {

        CourseOrder order = orderService.findByOrderId(order_id);
        model.addAttribute("order", order);

        return "courseOrder/detail";
    }

    @RequestMapping("/listJson")
    @ResponseBody
    /**
     * page: 显示的当前页
     * limit: 每次显示多少条
     */
    public PageResult<CourseOrder> listJson(int page, int limit) {

        PageResult<CourseOrder> result = orderService.findPageResult(null, page, limit);

        return result;
    }

}
